package com.yearner.reviewplan.manage.system;

import com.yearner.reviewplan.common.aspect.AuthTokenV1;
import com.yearner.reviewplan.common.model.Result;
import com.yearner.reviewplan.manage.system.entity.UserRole;
import com.yearner.reviewplan.manage.system.service.UserRoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;


/**
 * 角色表
 *
 * @author Pengyg
 */
@Api
@RestController
@RequestMapping("/api/system/userrole")
public class UserRoleController {
    @Autowired
    private UserRoleService userRoleService;

    /**
     * 列表
     */
    @AuthTokenV1
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        userRoleService.list(params);
        return Result.success(userRoleService.list());
    }


    /**
     * 信息详情
     */
    @AuthTokenV1
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") String id){
		UserRole userRole = userRoleService.getById(id);

        return Result.success(userRole);
    }

    /**
     * 保存
     */
    @AuthTokenV1
    @RequestMapping("/save")
    public Result save(@RequestBody UserRole entity){
        userRoleService.save(entity);
        return Result.success();
    }


    public Result allotRole(@RequestBody List<Integer> uids,List<String> perms) {
        // 分配角色
        return Result.success();
    }

    /**
     * 修改
     */
    @AuthTokenV1
    @RequestMapping("/update")
    public Result update(@RequestBody UserRole entity){
		userRoleService.updateById(entity);

        return Result.success();
    }

    /**
     * 删除
     */
    @AuthTokenV1
    @RequestMapping("/delete")
    public Result delete(@RequestBody Integer[] ids){
		userRoleService.removeByIds(Collections.singletonList(ids));

        return Result.success();
    }

}
